<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="收房贷申请ID" prop="sfLoanId">
        <el-input
          v-model="queryParams.sfLoanId"
          placeholder="请输入收房贷申请ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商户ID" prop="businessId">
        <el-input
          v-model="queryParams.businessId"
          placeholder="请输入商户ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部门ID" prop="deptId">
        <el-input
          v-model="queryParams.deptId"
          placeholder="请输入部门ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部门编号" prop="deptNo">
        <el-input
          v-model="queryParams.deptNo"
          placeholder="请输入部门编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="房产编号" prop="houseId">
        <el-input
          v-model="queryParams.houseId"
          placeholder="请输入房产编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="房产信息(考虑在房产表中增加house_name，然后带出)" prop="houseName">
        <el-input
          v-model="queryParams.houseName"
          placeholder="请输入房产信息(考虑在房产表中增加house_name，然后带出)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="房产编号" prop="houseNo">
        <el-input
          v-model="queryParams.houseNo"
          placeholder="请输入房产编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="账期还款金额" prop="repaymentAmount">
        <el-input
          v-model="queryParams.repaymentAmount"
          placeholder="请输入账期还款金额"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="本金" prop="capital">
        <el-input
          v-model="queryParams.capital"
          placeholder="请输入本金"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="账期利息" prop="rateAmount">
        <el-input
          v-model="queryParams.rateAmount"
          placeholder="请输入账期利息"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="第几期" prop="payNumber">
        <el-input
          v-model="queryParams.payNumber"
          placeholder="请输入第几期"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="借款账期开始日‘yyyymmdd’" prop="loStartTime">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.loStartTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择借款账期开始日‘yyyymmdd’">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="借款账期截止日'yyyymmdd'" prop="loEndTime">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.loEndTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择借款账期截止日'yyyymmdd'">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="预留字段1" prop="reserve1">
        <el-input
          v-model="queryParams.reserve1"
          placeholder="请输入预留字段1"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预留字段2" prop="reserve2">
        <el-input
          v-model="queryParams.reserve2"
          placeholder="请输入预留字段2"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预留字段3" prop="reserve3">
        <el-input
          v-model="queryParams.reserve3"
          placeholder="请输入预留字段3"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预留字段4" prop="reserve4">
        <el-input
          v-model="queryParams.reserve4"
          placeholder="请输入预留字段4"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预留字段5" prop="reserve5">
        <el-input
          v-model="queryParams.reserve5"
          placeholder="请输入预留字段5"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="删除标识 0:未删除，1:删除" prop="delFlg">
        <el-input
          v-model="queryParams.delFlg"
          placeholder="请输入删除标识 0:未删除，1:删除"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建用户ID" prop="createUserid">
        <el-input
          v-model="queryParams.createUserid"
          placeholder="请输入创建用户ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="更新用户ID" prop="updateUserid">
        <el-input
          v-model="queryParams.updateUserid"
          placeholder="请输入更新用户ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:detail:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:detail:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:detail:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:detail:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="detailList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="收房贷申请ID" align="center" prop="sfLoanId" />
      <el-table-column label="商户ID" align="center" prop="businessId" />
      <el-table-column label="部门ID" align="center" prop="deptId" />
      <el-table-column label="部门编号" align="center" prop="deptNo" />
      <el-table-column label="房产编号" align="center" prop="houseId" />
      <el-table-column label="房产信息(考虑在房产表中增加house_name，然后带出)" align="center" prop="houseName" />
      <el-table-column label="房产编号" align="center" prop="houseNo" />
      <el-table-column label="账期还款金额" align="center" prop="repaymentAmount" />
      <el-table-column label="本金" align="center" prop="capital" />
      <el-table-column label="账期利息" align="center" prop="rateAmount" />
      <el-table-column label="第几期" align="center" prop="payNumber" />
      <el-table-column label="借款账期开始日‘yyyymmdd’" align="center" prop="loStartTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.loStartTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="借款账期截止日'yyyymmdd'" align="center" prop="loEndTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.loEndTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="预留字段1" align="center" prop="reserve1" />
      <el-table-column label="预留字段2" align="center" prop="reserve2" />
      <el-table-column label="预留字段3" align="center" prop="reserve3" />
      <el-table-column label="预留字段4" align="center" prop="reserve4" />
      <el-table-column label="预留字段5" align="center" prop="reserve5" />
      <el-table-column label="删除标识 0:未删除，1:删除" align="center" prop="delFlg" />
      <el-table-column label="创建用户ID" align="center" prop="createUserid" />
      <el-table-column label="更新用户ID" align="center" prop="updateUserid" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:detail:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:detail:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改收房贷申请明细对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="收房贷申请ID" prop="sfLoanId">
          <el-input v-model="form.sfLoanId" placeholder="请输入收房贷申请ID" />
        </el-form-item>
        <el-form-item label="商户ID" prop="businessId">
          <el-input v-model="form.businessId" placeholder="请输入商户ID" />
        </el-form-item>
        <el-form-item label="部门ID" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入部门ID" />
        </el-form-item>
        <el-form-item label="部门编号" prop="deptNo">
          <el-input v-model="form.deptNo" placeholder="请输入部门编号" />
        </el-form-item>
        <el-form-item label="房产编号" prop="houseId">
          <el-input v-model="form.houseId" placeholder="请输入房产编号" />
        </el-form-item>
        <el-form-item label="房产信息(考虑在房产表中增加house_name，然后带出)" prop="houseName">
          <el-input v-model="form.houseName" placeholder="请输入房产信息(考虑在房产表中增加house_name，然后带出)" />
        </el-form-item>
        <el-form-item label="房产编号" prop="houseNo">
          <el-input v-model="form.houseNo" placeholder="请输入房产编号" />
        </el-form-item>
        <el-form-item label="账期还款金额" prop="repaymentAmount">
          <el-input v-model="form.repaymentAmount" placeholder="请输入账期还款金额" />
        </el-form-item>
        <el-form-item label="本金" prop="capital">
          <el-input v-model="form.capital" placeholder="请输入本金" />
        </el-form-item>
        <el-form-item label="账期利息" prop="rateAmount">
          <el-input v-model="form.rateAmount" placeholder="请输入账期利息" />
        </el-form-item>
        <el-form-item label="第几期" prop="payNumber">
          <el-input v-model="form.payNumber" placeholder="请输入第几期" />
        </el-form-item>
        <el-form-item label="借款账期开始日‘yyyymmdd’" prop="loStartTime">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.loStartTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择借款账期开始日‘yyyymmdd’">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="借款账期截止日'yyyymmdd'" prop="loEndTime">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.loEndTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择借款账期截止日'yyyymmdd'">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="预留字段1" prop="reserve1">
          <el-input v-model="form.reserve1" placeholder="请输入预留字段1" />
        </el-form-item>
        <el-form-item label="预留字段2" prop="reserve2">
          <el-input v-model="form.reserve2" placeholder="请输入预留字段2" />
        </el-form-item>
        <el-form-item label="预留字段3" prop="reserve3">
          <el-input v-model="form.reserve3" placeholder="请输入预留字段3" />
        </el-form-item>
        <el-form-item label="预留字段4" prop="reserve4">
          <el-input v-model="form.reserve4" placeholder="请输入预留字段4" />
        </el-form-item>
        <el-form-item label="预留字段5" prop="reserve5">
          <el-input v-model="form.reserve5" placeholder="请输入预留字段5" />
        </el-form-item>
        <el-form-item label="删除标识 0:未删除，1:删除" prop="delFlg">
          <el-input v-model="form.delFlg" placeholder="请输入删除标识 0:未删除，1:删除" />
        </el-form-item>
        <el-form-item label="创建用户ID" prop="createUserid">
          <el-input v-model="form.createUserid" placeholder="请输入创建用户ID" />
        </el-form-item>
        <el-form-item label="更新用户ID" prop="updateUserid">
          <el-input v-model="form.updateUserid" placeholder="请输入更新用户ID" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDetail, getDetail, delDetail, addDetail, updateDetail } from "@/api/system/detail";

export default {
  name: "Detail",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 收房贷申请明细表格数据
      detailList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sfLoanId: null,
        businessId: null,
        deptId: null,
        deptNo: null,
        houseId: null,
        houseName: null,
        houseNo: null,
        repaymentAmount: null,
        capital: null,
        rateAmount: null,
        payNumber: null,
        loStartTime: null,
        loEndTime: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        updateUserid: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        sfLoanId: [
          { required: true, message: "收房贷申请ID不能为空", trigger: "blur" }
        ],
        businessId: [
          { required: true, message: "商户ID不能为空", trigger: "blur" }
        ],
        deptId: [
          { required: true, message: "部门ID不能为空", trigger: "blur" }
        ],
        houseId: [
          { required: true, message: "房产编号不能为空", trigger: "blur" }
        ],
        houseName: [
          { required: true, message: "房产信息(考虑在房产表中增加house_name，然后带出)不能为空", trigger: "blur" }
        ],
        repaymentAmount: [
          { required: true, message: "账期还款金额不能为空", trigger: "blur" }
        ],
        capital: [
          { required: true, message: "本金不能为空", trigger: "blur" }
        ],
        rateAmount: [
          { required: true, message: "账期利息不能为空", trigger: "blur" }
        ],
        delFlg: [
          { required: true, message: "删除标识 0:未删除，1:删除不能为空", trigger: "blur" }
        ],
        createUserid: [
          { required: true, message: "创建用户ID不能为空", trigger: "blur" }
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        updateUserid: [
          { required: true, message: "更新用户ID不能为空", trigger: "blur" }
        ],
        updateTime: [
          { required: true, message: "更新时间不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询收房贷申请明细列表 */
    getList() {
      this.loading = true;
      listDetail(this.queryParams).then(response => {
        this.detailList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        sfLoanId: null,
        businessId: null,
        deptId: null,
        deptNo: null,
        houseId: null,
        houseName: null,
        houseNo: null,
        repaymentAmount: null,
        capital: null,
        rateAmount: null,
        payNumber: null,
        loStartTime: null,
        loEndTime: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        createTime: null,
        updateUserid: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加收房贷申请明细";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDetail(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改收房贷申请明细";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDetail(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addDetail(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除收房贷申请明细编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delDetail(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/detail/export', {
        ...this.queryParams
      }, `system_detail.xlsx`)
    }
  }
};
</script>
